package tazadum.engine.event;

public class PeriodicSyncEventChannel implements SyncEventChannel {
	private final float offset;
	private final float period;
	private final boolean early;

	/**
	 * 
	 * @param period
	 * @param offset
	 * @param early
	 *            If the switch of event time should be early or late.
	 */
	public PeriodicSyncEventChannel(final float period, final float offset, final boolean early) {
		this.period = period;
		this.offset = offset;
		this.early = early;
	}

	public float offset() {
		return offset;
	}

	public float period() {
		return period;
	}

	@Override
	public void add(final float time) {
		throw new UnsupportedOperationException("add is not implemented");
	}

	@Override
	public void add(final float... time) {
		throw new UnsupportedOperationException("add is not implemented");
	}

	@Override
	public float get(final float time) {
		if (early)
			return (float) Math.floor((time - offset) / period) * period;
		return (float) Math.ceil((time - offset) / period) * period;
	}
}
